package com.example.exam.post.service;

import com.example.exam.db.PageInfoBean;
import com.example.exam.post.dao.PostDao;
import com.example.exam.post.model.PostBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PostService {
    @Autowired
    PostDao postDao;
    /**
     * @Description:添加岗位
     * @Param: [postBean]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer addPost(PostBean postBean){

        Integer i=postDao.add(postBean);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }/**
     * @Description:删除岗位
     * @Param: [id]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer delete(Integer id){
        Integer i=postDao.deleteById(id);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }
    /**
     * @Description:查询一条岗位信息
     * @Param: [id]
     * @return: com.example.exam.post.model.PostBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public PostBean findById(Integer id){

        PostBean postBean=postDao.findById(id);
        if(postBean!=null){
            return postBean;
        }else{
            return null;
        }
    }
    /**
     * @Description:修改岗位信息
     * @Param: [postBean]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer update (PostBean postBean){

        Integer i=postDao.update(postBean);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }
    /**
     * @Description:获取岗位信息列表
     * @Param: [page, limit, name]
     * @return: com.example.exam.db.PageInfoBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public PageInfoBean list(Integer page,Integer limit,String name){

        try {
            PageInfoBean pageInfoBean = new PageInfoBean();
            pageInfoBean.setPerPage(limit);
            if(page != null) {
                pageInfoBean.setCurPage(page);
            }
            PageInfoBean pageInfo = postDao.list(pageInfoBean,name);
            return pageInfo;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * @Description:查询岗位编号和姓名作为员工信息岗位的下拉框数据
     * @Param: []
     * @return: java.util.List<com.example.exam.post.model.PostBean>
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public List<PostBean> listPost(){
        List<PostBean> list=postDao.listPost();
        if(list!=null){
            return list;
        }else{
            return null;
        }
    }
}
